/*
 * Copyright © 2022-now 尛飛俠（Denvie） All rights reserved.
 */

package cn.denvie.springcloud.seata.common.model.vo;

import org.apache.commons.lang3.math.NumberUtils;

/**
 * ResultVo。
 *
 * @author Denvie
 * @date 2022/4/8
 * @since 1.0.0
 */
public class ResultVo<T> {
    /**
     * 结果成功码
     */
    public static final int SUCCESS_CODE = 0;
    /**
     * 结果失败码
     */
    public static final int FAIL_CODE = -1;

    private int code;
    private String message;
    private T data;

    public ResultVo() {
        this.code = SUCCESS_CODE;
        this.message = "success";
    }

    public static ResultVo<Void> ok(String msg) {
        ResultVo<Void> resultVo = new ResultVo<>();
        resultVo.message = msg;
        return resultVo;
    }

    public static <T> ResultVo<T> ok(T data) {
        ResultVo<T> resultVo = new ResultVo<>();
        resultVo.data = data;
        return resultVo;
    }

    public static <T> ResultVo<T> ok(String msg, T data) {
        ResultVo<T> resultVo = new ResultVo<>();
        resultVo.message = msg;
        resultVo.data = data;
        return resultVo;
    }

    public static ResultVo<Void> ok() {
        return new ResultVo<>();
    }

    public static ResultVo<Void> error(int code, String msg) {
        ResultVo<Void> resultVo = new ResultVo<>();
        resultVo.code = code;
        resultVo.message = msg;
        return resultVo;
    }

    public static ResultVo<Void> error(String msg) {
        ResultVo<Void> resultVo = new ResultVo<>();
        resultVo.code = FAIL_CODE;
        resultVo.message = msg;
        return resultVo;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }
}
